package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.pojo.Member;
import com.itheima.service.MemberService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/report")
public class ReportMemberController {
    @Reference
    private MemberService memberService;
    @RequestMapping("/getMemberReport")
    public Result getMemberReport() {
       //创建一个hashmap容器用于装月份和用户量数据
        HashMap<String, Object> hashMap = new HashMap<>();
        List<String> month = new ArrayList<>();

        //获取当前时间   calender函数
        Calendar calendar = Calendar.getInstance();
        //时间推移  add为计算方法
        calendar.add(Calendar.MONTH, -12);
        for (int i = 0; i <12 ; i++) {
            calendar.add(Calendar.MONTH,1);
            SimpleDateFormat format = new SimpleDateFormat("yyyy.MM");
            String format1 = format.format(calendar.getTime());
            month.add(format1);
        }
        hashMap.put("months",month);

        List<Integer> memberCountByMonth = memberService.findMemberCountByMonth(month);

        hashMap.put("memberCount",memberCountByMonth);


        return new Result(true, "终于完成了", hashMap);

    }

}
